package com.zzsh.redisson.study;

import org.redisson.Redisson;
import org.redisson.api.RLock;
import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

/**
 * @author liushiqiao
 * @create 2021-09-22 6:03
 * @description
 * @menu
 **/
public class Demo {

    public static void main(String[] args) throws InterruptedException {

        Config config = new Config();
        config.useClusterServers()
                .setPassword("123456")
                .addNodeAddress("redis://182.42.113.98:7001")
                .addNodeAddress("redis://182.42.113.98:7002")
                .addNodeAddress("redis://182.42.113.98:7003")
                .addNodeAddress("redis://182.42.113.98:7004")
                .addNodeAddress("redis://182.42.113.98:7005")
                .addNodeAddress("redis://182.42.113.98:7006");

        RedissonClient redissonClient = Redisson.create(config);

        RLock lock = redissonClient.getLock("anyLock");
        lock.lock();

        lock.lock();

        Thread.sleep(1000);
        lock.unlock();
        RMap<String, Object> anyMap = redissonClient.getMap("anyMap");
        anyMap.put("foo", "bar");

        System.out.println(redissonClient.getMap("anyMap").get("foo"));
    }
}
